#ifndef DATETIME_H
#define DATETIME_H

#include <stdint.h>

typedef struct
{
    uint8_t year;
    uint8_t month; //!< 1- 12
    uint8_t day;
} date_t;

typedef struct
{
    uint8_t hour;
    uint8_t minute;
    uint8_t second;
} time_t;

typedef struct
{
    date_t date;
    time_t time;
} datetime_t;

typedef uint16_t indexday_t;
uint8_t DateIsLeapYear(uint16_t year);
uint8_t DateMonthDays(uint8_t year, uint8_t month);
uint8_t DateDayWeek(uint8_t year, uint8_t month, uint8_t day);
void print_utc_time(uint32_t utc);
int16_t DateCompare(date_t *date1, date_t *date2);
date_t DateBeforeDay(date_t *date, uint16_t day); // 求几天前的日期

int32_t TimeCompare(time_t *time1, time_t *time2);

//将UTC时间转换为本地日期时间
void UTCToLocal(uint8_t time_zone, datetime_t *utc, datetime_t *local);

uint32_t DateUTCtoSecond(datetime_t *utc);
datetime_t DateSecondtoUTC(uint32_t Secs);
datetime_t utc_time_to_date_time(uint32_t utc);
uint32_t date_time_to_utc(datetime_t *utc);
// void DateTicksToTime(time_t *t, uint16_t *ms);

datetime_t DateSync(void);
void rtc_get_time(time_t *p_time);
uint16_t date_to_days(date_t *p_date);
indexday_t get_present_indexday(void);
uint16_t get_present_day_minute(void);
uint8_t get_present_week(void);
uint8_t get_week_from_seconds(uint32_t sec);
indexday_t get_indexday_from_secs(uint32_t secs);
uint32_t get_ms(void);
#endif
